/*
 * $Id: Attachment.java,v 1.5 2009/07/15 16:35:33 oliver Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.util.mail;

import javax.activation.FileDataSource;

import com.ge.healthcare.autosc.common.ASCUtil;

/**
 * 
 * @author 212042946 This class stores attachment information
 */
public class Attachment {

	// private String contentType = null;
	private String attachmentName = null;
	private String attachmentFileSource = null;

	/**
	 * Constructor
	 */
	public Attachment() {
	}

	/**
	 * Constructor
	 * 
	 * @param attachmentName
	 * @param attachmentFileSource
	 * @param contentType
	 */
	public Attachment(String attachmentName, String attachmentFileSource,
			String contentType) {
		// this.contentType = contentType;
		this.attachmentName = attachmentName;
		this.attachmentFileSource = attachmentFileSource;
	}

	/*
	 * public String getContentType() { return contentType; }
	 */
	/*
	 * public void setContentType(String contentType) { this.contentType =
	 * contentType; }
	 */
	/**
	 * Get the attachment name. The name use as the name of the attachment
	 */
	public String getAttachmentName() {
		return attachmentName;
	}

	/**
	 * Set attachment name
	 * 
	 * @param attachmentName
	 */
	public void setAttachmentName(String attachmentName) {
		this.attachmentName = attachmentName;
	}

	/**
	 * Get attachment source as data source format
	 * 
	 * @return
	 */
	public FileDataSource getAttachmentDS() {
		if (attachmentFileSource != null) {
			return (new FileDataSource(attachmentFileSource));
		}
		return null;
	}

	/**
	 * This should be the physical path to the file
	 * 
	 * @return
	 */
	public String getAttachmentFileName() {
		return this.attachmentFileSource;
	}

	/**
	 * Set attachment file name
	 * 
	 * @param fileName
	 */
	public void setAttachmentFileName(String fileName) {
		this.attachmentFileSource = fileName;
	}

	/**
	 * Determine if the attachment is valid. It is valid if
	 * <ul>
	 * <li>Attachment name and file name are defined.
	 * <li>Attachment exists as a file
	 * </ul>
	 * 
	 * @return
	 */
	public boolean isValidAttachment() {
		if ((ASCUtil.isNullOrEmpty(this.attachmentName))
				|| (ASCUtil.isNullOrEmpty(this.attachmentFileSource))) {
			return false;
		} else {
			FileDataSource fileDs = getAttachmentDS();
			if ((!fileDs.getFile().exists()) || (!fileDs.getFile().isFile())) {
				return false;
			}
			return true;
		}
	}

	/**
	 * Print the attachment information
	 */
	public String toString() {
		StringBuffer msg = new StringBuffer();
		msg.append("Attachment Name: " + this.getAttachmentName());
		msg.append("\n");
		msg.append("File Name: " + this.getAttachmentFileName());
		msg.append("\n");
		return msg.toString();
	}
}
